package cn.zhf.shop.controller;

import cn.hutool.json.JSONUtil;
import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.Refund;
import cn.zhf.shop.service.RefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.logging.Logger;

@RestController
@Api(tags = "退款申请模块")
@RequestMapping("/api/refund/")
public class RefundController {

    @Resource
    private RefundService refundService;

    @PostMapping("/")
    @ApiOperation(value = "新增退款申请")
    public Message<?> insert(Refund r){
        return refundService.insert(r);
    }

    @GetMapping("/orderId")
    @ApiOperation(value = "根据订单编号获取退款申请")
    public Message<Refund> selectByOrderId(String orderId){
        return refundService.selectByOrderId(orderId);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有退款申请")
    public Message<List<Refund>> selectAll(){
        return refundService.selectAll();
    }

    @GetMapping("/userId")
    @ApiOperation(value = "根据userId获取退款申请")
    public Message<List<Refund>> selectByUserId(String userId){
        return refundService.selectByUserId(userId);
    }


    @GetMapping("/state")
    @ApiOperation(value = "根据退款申请状态获取申请")
    public Message<List<Refund>> selectByState(Integer state)
    {
        return refundService.selectByState(state);
    }

    @GetMapping("/stateAndUserId")
    @ApiOperation(value = "根据订单状态与用户状态获取订单")
    public Message<List<Refund>> selectByUserIdAndState(String userId,Integer state){
        return refundService.selectByUserIdAndState(userId, state);
    }

    @PutMapping("/")
    @ApiOperation(value = "更新退款状态")
    public Message<?> updatePayState(HttpServletRequest req, String orderId, Integer state){
//        System.out.println("orderId:"+orderId);
//        System.out.println(req.getParameter("orderId"));
////        return null;
        return refundService.updateState(orderId,state);
    }

}

